﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;
namespace chatblog
{
    public partial class jinghua : System.Web.UI.Page
    {
        cbarea area;
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            {
                cbuser.dealcookie();
                dealrequest();
                bind1();
                bind2();
                //bind3();
            }
        }
        private void dealrequest()
        {

            area = cbarea.getcurarea();
            if (area.enableareabtn.Value == RuleCode.Enum.NoYes.No)
            {
                Panel_area.Visible = false;
            }
            if (area.enableask.Value == RuleCode.Enum.NoYes.Yes)
            {
                Panel_q.Visible = true;
            }
            Literal_logolink.Text = area.getlogolink();

        }

        private void bind1()
        {
            DataTable a1;
            string sql = "";
            //今日发帖量
            sql = " select count(*) from vcblist where cbstatus = '有效' "
                + " and jccreatedate <= '" + DateTime.Today.AddDays(1).ToShortDateString()
                + "' and jccreatedate >= '" + DateTime.Today.ToShortDateString() + "' "
               + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' or cbcatastatus = '全部')";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            Label_today.Text = a1.Rows[0].ItemArray[0].ToString();
            //昨日发帖量
            sql = " select count(*) from vcblist where cbstatus = '有效' "
                + " and jccreatedate <= '" + DateTime.Today.ToShortDateString()
                + "' and jccreatedate >= '" + DateTime.Today.AddDays(-1).ToShortDateString() + "' "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' or cbcatastatus = '全部')";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            Label_yestoday.Text = a1.Rows[0].ItemArray[0].ToString();
            //总发帖量
            sql = " select count(*) from vcblist where cbstatus = '有效' "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' or cbcatastatus = '全部')";
            a1 = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            Label_sum.Text = a1.Rows[0].ItemArray[0].ToString();
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void bind2()
        {
            string sql = "";

            sql = " select top 1000 * from vcblist where isprivate != 1 ";
            if (AliApi.appInstanceId != "")
            {
                sql += " and area = '" + AliApi.appInstanceId + "' ";
            }
            if (this.Request.Params["cbcataid"] != null)
            {
                sql += " and  cbcataid = '" + this.Request.Params["cbcataid"] .ToString()+ "' ";
            }
            sql += " and  jinghua = 1 ";
            sql += " and  cblisttype = '发帖' "
                + " and ( cbcatastatus = '" + area.cbareaid.ToString()
                + "' or cbcatastatus = '全部')";
            sql += "  order by jccreatedate desc ,jccreatetime desc ";
            DataTable dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            WebPager_all.DataSource = dt;
            WebPager_all.DataBind();
        }
        protected void Button_all_Click(object sender, EventArgs e)
        {
            cbuser.setarea("");
            bind2();
            bind3();
        }

        protected void Button_bj_Click(object sender, EventArgs e)
        {
            cbuser.setarea("北京");
            bind2();
            bind3();
        }

        protected void Button_sh_Click(object sender, EventArgs e)
        {
            cbuser.setarea("上海");
            bind2();
            bind3();
        }

        protected void Button_gz_Click(object sender, EventArgs e)
        {
            cbuser.setarea("广东");
            bind2();
            bind3();
        }

        protected void Button_qt_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this.Button_qt, this.Button_qt.GetType(), "selectbuttonclick",
"<script type =\"text/javascript\" >selectButtonClick('" + this.Label_area.ClientID + "');</script>", false);
            bind2();
            bind3();
        }

        protected void Button_ok_Click(object sender, EventArgs e)
        {
            bind2();
        }

        private void bind3()
        {
        }
        protected void WebPager_all_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            bind2();
            WebPager_all.CurrentPageIndex = e.NewPageIndex;
        }
    }
}
